
#include "dragonet.h"

static struct proto_ops dragonet_ops;

static int 
drg_create(struct net *net, struct socket *sock, int protocol, int kern)
{ 
	int ret = -ENOMEM;
	struct sock *sk;
	
	/* sanity check */
	if (protocol && protocol != PF_UNIX)
		return -EPROTONOSUPPORT;

	if (sock->type != SOCK_RAW)
		return -ESOCKTNOSUPPORT;

	if (protocol != htons(ETH_P_ALL))
		return -EPROTONOSUPPORT;

	sk = sk_alloc(net, PF_INET, GFP_KERNEL, &ring_proto);
	if (!sk)
		goto out;

	sock->ops = &dragonet_ops;
	sock_init_data(sock, sk);


	return 0;

out:
	return ret;
}

static struct proto_ops dragonet_ops = {
	.family = PF_DRAGONET,
	.owner = THIS_MODULE,

	/* Operations that make no sense on ring sockets. */
	.connect = sock_no_connect,
	.socketpair = sock_no_socketpair,
	.accept = sock_no_accept,
	.getname = sock_no_getname,
	.listen = sock_no_listen,
	.shutdown = sock_no_shutdown,
	.sendpage = sock_no_sendpage,

#if 0
	/* Now the operations that really occur. */
	.release = ring_release,
	.bind = ring_bind,
	.mmap = ring_mmap,
	.poll = ring_poll,
	.setsockopt = ring_setsockopt,
	.getsockopt = ring_getsockopt,
	.ioctl = ring_ioctl,
	.recvmsg = ring_recvmsg,
	.sendmsg = ring_sendmsg,
#endif
};

static struct proto dragonet_proto = {
	.name = "DRAGONET",
	.owner = THIS_MODULE,
	.obj_size = sizeof(struct drg_sock),
};

static struct net_proto_family dragonet_family_ops = {
	.family = PF_DRAGONET,
	.create = drg_create,
	.owner = THIS_MODULE,
};


int 
drg_sock_init(void)
{
	return sock_register(&dragonet_family_ops);
}

void 
drg_sock_exit(void)
{
	sock_unregister(PF_DRAGONET);
}

